var http = require('../../utils/http.js');
var util = require('../../utils/util.js');
var unionid = wx.getStorageSync('thisCode');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabFlag: true,
        imgUrl: http.imgUrl,
        exchangeArr: ['全部', '获得', '使用'],
        exchangeIndex: 0,
        dataBottom: {
            flage: false,
            list: [],
            frist: true
        },
        data: {
            name: '哎呀，您还没有积分呐！'
        },
        inteArr: [],
        exchangeDataArr: [{
            a: '本月',
            b: 4,
            c: 5,
            d: 6,
            arr: [{
                a: '兑换无敌西瓜卷',
                b: '2018-02-01 12:23',
                c: '2019-02-01 12:23',
                d: 1
            }, {
                a: '兑换无敌西瓜卷',
                b: '2018-02-01 12:23',
                c: '2019-02-01 12:23',
                d: 2
            }, ]
        }, {
            a: '一月',
            b: 4,
            c: 5,
            d: 6,
            arr: [{
                a: '兑换无敌西瓜卷',
                b: '2018-02-01 12:23',
                c: '2019-02-01 12:23',
                d: 1
            }, {
                a: '兑换无敌西瓜卷',
                b: '2018-02-01 12:23',
                c: '2019-02-01 12:23',
                d: 3
            }, ]
        }, {
            a: '二月',
            b: 4,
            c: 5,
            d: 6,
            arr: [{
                a: '兑换无敌西瓜卷',
                b: '2018-02-01 12:23',
                c: '2019-02-01 12:23',
                d: 1
            }]
        }, ],
        loading: false,
        paging: 1
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let scrollH = Number(util.nowPhoneWH()[1]) - (70 + 60);
        this.setData({ scrollH: scrollH });
        this.startFn(1)
    },
    tabarChangeBtn(e) {
        let index = http.dataIndex(e)[0];
        // let tabFlag = index==0?true:false;
        let tabTxt = index == 0 ? '哎呀，您还没有积分呐！' : '哎呀，您还没有兑换记录呐！';
        if (index == 1) http.showModal('尽请期待！', false, () => {})
        this.setData({
            // tabFlag: tabFlag,
            data: {
                name: tabTxt
            }
        })

    },
    startFn(paging) {
        wx.showLoading({ title: '加载中...', })
        http._post('Integral/integral_list', { paging }, res => {
            let data = res.data;
            if (data.status == 1) {
                let inteArr = paging == 1 ? [] : this.data.inteArr;
                let allnum = data.card_point_balance
                for (let item of data.list) {
                    inteArr.push(item)
                }
                this.setData({ inteArr, loading: true, allnum, hasNext: data.hasNext, paging })
            }
        }, res => {})
    },
    exchange: function(e) {
        this.setData({
            exchangeIndex: e.detail.value
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },
    // 积分明细触底事件
    inteBottomFn() {
        let paging = this.data.paging
        if (this.data.hasNext) {
            paging++;
            this.startFn(paging)
        } else {
            this.setData({
                dataBottom: {
                    flage: true,
                    list: [],
                    frist: true
                },
            })
        }
    },
    // 兑换记录触底事件
    exchangeBottomFn() {

    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        wx.hideShareMenu();
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    }
})